




// 选择流程执行人弹框
function entrust() {
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/technological/delegation", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var JsonDate = JSON.parse(xhr.responseText);
                console.log(JsonDate);
                window.personnel_list = JsonDate["data"];
                var department_list = document.getElementById("department_list");
                department_list.innerHTML = "";
                var ul_tag = document.createElement("ul");
                for (var i=0; i<JsonDate["branch_list"].length; i++) {
                    var li_tag = document.createElement("li");
                    li_tag.innerHTML = JsonDate["branch_list"][i];li_tag.setAttribute("onclick", "choice_peopel('"+JsonDate["branch_list"][i]+"')");li_tag.className="li-class";
                    ul_tag.appendChild(li_tag);
                    department_list.appendChild(ul_tag);
                }
            }
        }
    };
}

// 选择流程执行人弹框
function entrust1() {
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/technological/delegation", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var JsonDate = JSON.parse(xhr.responseText);
                console.log(JsonDate);
                window.personnel_list = JsonDate["data"];
                var department_list = document.getElementById("department_list1");
                department_list.innerHTML = "";
                var ul_tag = document.createElement("ul");
                for (var i=0; i<JsonDate["branch_list"].length; i++) {
                    var li_tag = document.createElement("li");
                    li_tag.innerHTML = JsonDate["branch_list"][i];li_tag.setAttribute("onclick", "choice_peopel1('"+JsonDate["branch_list"][i]+"')");li_tag.className="li-class";
                    ul_tag.appendChild(li_tag);
                    department_list.appendChild(ul_tag);
                }
            }
        }
    };
}

// 创建右侧选择人员列表
function choice_peopel(choice_key) {
    var personnel_list = window.personnel_list;
    document.getElementById("img-display1").style.display = "none";
    var t_table = document.getElementById("t_table2");
    deltr1();
    for (var i=0; i<personnel_list[choice_key].length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");
        td.innerHTML = "<input id='"+personnel_list[choice_key][i]+"' class='check_box' type=\"checkbox\" onclick='choice_consignor(this.id)'>";td.style.textAlign = "center";
        td1.innerHTML = i+1;td1.style.textAlign = "center";
        td2.innerHTML = personnel_list[choice_key][i];td2.title =personnel_list[choice_key][i];td2.style.textAlign = "center";

        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);
        t_table.appendChild(tr);
    }
}


// 创建右侧选择人员列表
function choice_peopel1(choice_key) {
    var personnel_list = window.personnel_list;
    document.getElementById("img-display2").style.display = "none";
    var t_table = document.getElementById("t_table3");
    deltr2();
    for (var i=0; i<personnel_list[choice_key].length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");
        td.innerHTML = "<input id='"+personnel_list[choice_key][i]+"' class='check_box' type=\"checkbox\" onclick='choice_consignor1(this.id)'>";td.style.textAlign = "center";
        td1.innerHTML = i+1;td1.style.textAlign = "center";
        td2.innerHTML = personnel_list[choice_key][i];td2.title =personnel_list[choice_key][i];td2.style.textAlign = "center";

        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);
        t_table.appendChild(tr);
    }
}

// 删除列表
function deltr1(){
    var tb = document.getElementById('t_table2');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}

// 删除列表
function deltr2(){
    var tb = document.getElementById('t_table3');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}

// 选择委托人
function choice_consignor(ele_id) {
    check_more_one_not(ele_id);
    document.getElementById("checked-label").innerHTML = "<span style='margin-left: 1%;'>"+ele_id+"</span>";
}

// 选择委托人
function choice_consignor1(ele_id) {
    check_more_one_not(ele_id);
    document.getElementById("checked-label1").innerHTML = "<span style='margin-left: 1%;'>"+ele_id+"</span>";
}

// checkBox不允许多选
function check_more_one_not(ele_id) {
    var check_box_list = document.getElementsByClassName("check_box");
    for (var i=0; i<check_box_list.length; i++){
        if (String(check_box_list[i].id) !== String(ele_id)){
            document.getElementById(check_box_list[i].id).checked = false;
        }else {
            document.getElementById(check_box_list[i].id).checked = true;
        }
    }
}


// 选择执行人
function summit_val(ele_id) {
    var executor = '';
    if (ele_id === "Administrative_person"){
        var checked_label = document.getElementById("checked-label1");
        for (var j=0; j<checked_label.children.length; j++){
            executor = executor+checked_label.children[j].innerText+", ";
        }
        document.getElementById("Administrative_person").setAttribute("value", executor.slice(0, -2));
        document.getElementById("close-model1").click();
    }else {
        checked_label = document.getElementById("checked-label");
        for (var t=0; t<checked_label.children.length; t++){
            executor = executor+checked_label.children[t].innerText+", ";
        }
        document.getElementById("executor").innerHTML = executor.slice(0, -2);
        document.getElementById("close-model").click();
    }
}



// 选择流程执行人弹框
function entrust4() {
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/technological/delegation", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var JsonDate = JSON.parse(xhr.responseText);
                window.personnel_list = JsonDate["data"];
                var department_list = document.getElementById("department_list4");
                department_list.innerHTML = "";
                var ul_tag = document.createElement("ul");
                for (var i=0; i<JsonDate["branch_list"].length; i++) {
                    var li_tag = document.createElement("li");
                    li_tag.innerHTML = JsonDate["branch_list"][i];li_tag.setAttribute("onclick", "choice_peopel4('"+JsonDate["branch_list"][i]+"')");li_tag.className="li-class";
                    ul_tag.appendChild(li_tag);
                    department_list.appendChild(ul_tag);
                }
            }
        }
    };
}


// 创建右侧选择人员列表
function choice_peopel4(choice_key) {
    var personnel_list = window.personnel_list;
    document.getElementById("img-display4").style.display = "none";
    var t_table = document.getElementById("t_table4");
    deltr4();
    for (var i=0; i<personnel_list[choice_key].length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");
        td.innerHTML = "<input id='"+personnel_list[choice_key][i]+"' class='check_box' type=\"checkbox\" onclick='choice_consignor4(this.id)'>";td.style.textAlign = "center";
        td1.innerHTML = i+1;td1.style.textAlign = "center";
        td2.innerHTML = personnel_list[choice_key][i];td2.title =personnel_list[choice_key][i];td2.style.textAlign = "center";

        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);
        t_table.appendChild(tr);
    }
}


// 删除列表
function deltr4(){
    var tb = document.getElementById('t_table4');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}


// 选择委托人
function choice_consignor4(ele_id) {
     var checked_label = document.getElementById("checked-label4");
     var span = document.createElement("span");
     span.innerHTML = ele_id;span.style.marginLeft="1%";
     checked_label.appendChild(span);
}


// 选择执行人
function summit_val4() {
    var executor = '';
    checked_label = document.getElementById("checked-label4");
    for (var t=0; t<checked_label.children.length; t++){
        executor = executor+checked_label.children[t].innerText+", ";
    }
    document.getElementById("of_personnel").innerText = executor.slice(0, -2);
    document.getElementById("close-model4").click();
}
